﻿#region 头注释
/******************************************************************************
文件名称    :   ChemistryImmunity.cs
创建日期    :   2011/5/29 10:49:12
功能描述    :   ChemistryImmunity实体类
修改日志    :   
    2011-05-29 10:49  马利
*******************************************************************************/
#endregion

using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using Newtonsoft.Json;
using Dare.Utilities.Data;

namespace Stone.Components.Entities
{
    /// <summary>
    /// ChemistryImmunity实体类
    /// </summary>
    public class ChemistryImmunity : EntityBase<ChemistryImmunity, long>
    {
        #region 构造函数

        /// <summary>
        /// 默认构造函数
        /// </summary>
        public ChemistryImmunity()
            : base()
        {
            base.xmlSerializer = new DefaultXmlSerializer(this);
            base.jsonSerializer = new DefaultJsonSerializer(this);
        }

        public override void Reset()
        {
            il2 = null;
            il6 = null;
            il8 = null;
            il10 = null;
            tnf = null;
            crp = null;
            neomycin = null;
            comment = null;
            timeStamp = DateTime.MinValue;
        }

        public override ChemistryImmunity CreateNew()
        {
            return new ChemistryImmunity();
        }

        #endregion

        #region 属性

        /// <summary>
        /// 获取实体类型
        /// </summary>
        public override EntityType EntityType
        {
            get { return EntityType.ChemistryImmunity; }
        }

        /// <summary>
        /// 获取或设置Il2
        /// </summary>
        public decimal? Il2
        {
            get { return il2; }
            set
            {
                if (entityState == EntityState.Saved && il2 != value) entityState = EntityState.Changed;
                il2 = value;
            }
        }
        protected decimal? il2;

        /// <summary>
        /// 获取或设置Il6
        /// </summary>
        public decimal? Il6
        {
            get { return il6; }
            set
            {
                if (entityState == EntityState.Saved && il6 != value) entityState = EntityState.Changed;
                il6 = value;
            }
        }
        protected decimal? il6;

        /// <summary>
        /// 获取或设置Il8
        /// </summary>
        public decimal? Il8
        {
            get { return il8; }
            set
            {
                if (entityState == EntityState.Saved && il8 != value) entityState = EntityState.Changed;
                il8 = value;
            }
        }
        protected decimal? il8;

        /// <summary>
        /// 获取或设置Il10
        /// </summary>
        public decimal? Il10
        {
            get { return il10; }
            set
            {
                if (entityState == EntityState.Saved && il10 != value) entityState = EntityState.Changed;
                il10 = value;
            }
        }
        protected decimal? il10;

        /// <summary>
        /// 获取或设置Tnf
        /// </summary>
        public decimal? Tnf
        {
            get { return tnf; }
            set
            {
                if (entityState == EntityState.Saved && tnf != value) entityState = EntityState.Changed;
                tnf = value;
            }
        }
        protected decimal? tnf;

        /// <summary>
        /// 获取或设置Crp
        /// </summary>
        public decimal? Crp
        {
            get { return crp; }
            set
            {
                if (entityState == EntityState.Saved && crp != value) entityState = EntityState.Changed;
                crp = value;
            }
        }
        protected decimal? crp;

        /// <summary>
        /// 获取或设置内霉素(6-10pg/ml)
        /// </summary>
        public decimal? Neomycin
        {
            get { return neomycin; }
            set
            {
                if (entityState == EntityState.Saved && neomycin != value) entityState = EntityState.Changed;
                neomycin = value;
            }
        }
        protected decimal? neomycin;

        /// <summary>
        /// 获取或设置备注
        /// </summary>
        public string Comment
        {
            get { return comment; }
            set
            {
                if (entityState == EntityState.Saved && comment != value) entityState = EntityState.Changed;
                comment = value;
            }
        }
        protected string comment;

        /// <summary>
        /// 获取或设置更新时间戳
        /// </summary>
        public DateTime TimeStamp
        {
            get { return timeStamp; }
            set
            {
                if (entityState == EntityState.Saved && timeStamp != value) entityState = EntityState.Changed;
                timeStamp = value;
            }
        }
        protected DateTime timeStamp;

        #endregion

        #region 方法

        #endregion

        #region 实体复制相关方法

        /// <summary>
        /// 复制当前实体属性到指定实体上
        /// </summary>
        /// <param name="entity">要把属性复制到的实体</param>
        /// <returns>返回传入的实体</returns>
        public override ChemistryImmunity CopyTo(ChemistryImmunity entity)
        {
            if (base.CopyTo(entity) == null) return null;

            entity.il2 = this.il2;
            entity.il6 = this.il6;
            entity.il8 = this.il8;
            entity.il10 = this.il10;
            entity.tnf = this.tnf;
            entity.crp = this.crp;
            entity.neomycin = this.neomycin;
            entity.comment = this.comment;
            entity.timeStamp = this.timeStamp;

            return entity;
        }

        #endregion

        #region 默认XML序列器类

        public class DefaultXmlSerializer : XmlSerializerBase, IEntityXmlSerializer<ChemistryImmunity>
        {
            ChemistryImmunity entity;
            public DefaultXmlSerializer(ChemistryImmunity entity)
                : base(entity.GetType().Name)
            {
                this.entity = entity;
            }

            public ChemistryImmunity Entity
            {
                get { return entity; }
                set { entity = value; }
            }

            protected override void BeforeReadXml()
            {
                entity.Reset();
            }

            /// <summary>
            /// 读取XML属性
            /// </summary>
            /// <param name="name">属性名</param>
            /// <param name="value">属性值</param>
            /// <param name="reader">XML读取器</param>
            internal override void ReadXmlAttribute(string name, string value, XmlReader reader)
            {
                switch (name)
                {
                    case "id":
                        entity.id = XmlConvert.ToInt64(value);
                        break;
                    case "timeStamp":
                        entity.timeStamp = new DateTime(long.Parse(value));
                        break;
                    case "entityState":
                        entity.entityState = (EntityState)Enum.Parse(typeof(EntityState), value, true);
                        break;
                }
            }

            /// <summary>
            /// 读取XML子节点
            /// </summary>
            /// <param name="name">节点名</param>
            /// <param name="reader">XML读取器</param>
            internal override void ReadXmlChildElement(string name, XmlReader reader)
            {
                switch (name)
                {
                    case "Il2":
                        entity.il2 = XmlConvert.ToDecimal(reader.ReadElementString());
                        break;
                    case "Il6":
                        entity.il6 = XmlConvert.ToDecimal(reader.ReadElementString());
                        break;
                    case "Il8":
                        entity.il8 = XmlConvert.ToDecimal(reader.ReadElementString());
                        break;
                    case "Il10":
                        entity.il10 = XmlConvert.ToDecimal(reader.ReadElementString());
                        break;
                    case "Tnf":
                        entity.tnf = XmlConvert.ToDecimal(reader.ReadElementString());
                        break;
                    case "Crp":
                        entity.crp = XmlConvert.ToDecimal(reader.ReadElementString());
                        break;
                    case "Neomycin":
                        entity.neomycin = XmlConvert.ToDecimal(reader.ReadElementString());
                        break;
                    case "Comment":
                        entity.comment = reader.ReadElementString();
                        break;
                }
            }

            /// <summary>
            /// 写入XML属性
            /// </summary>
            /// <param name="writer">XML编写器</param>
            internal override void WriteXmlAttributes(XmlWriter writer)
            {
                writer.WriteAttributeString("id", XmlConvert.ToString(entity.Id));
                writer.WriteAttributeString("timeStamp", entity.TimeStamp.Ticks.ToString());
                writer.WriteAttributeString("entityState", entity.EntityState.ToString());
            }

            /// <summary>
            /// 写入XML子节点
            /// </summary>
            /// <param name="writer">XML编写器</param>
            internal override void WriteXmlChildElements(XmlWriter writer)
            {
                if (entity.Il2 != null) writer.WriteElementString("Il2", XmlConvert.ToString(entity.Il2.Value));
                if (entity.Il6 != null) writer.WriteElementString("Il6", XmlConvert.ToString(entity.Il6.Value));
                if (entity.Il8 != null) writer.WriteElementString("Il8", XmlConvert.ToString(entity.Il8.Value));
                if (entity.Il10 != null) writer.WriteElementString("Il10", XmlConvert.ToString(entity.Il10.Value));
                if (entity.Tnf != null) writer.WriteElementString("Tnf", XmlConvert.ToString(entity.Tnf.Value));
                if (entity.Crp != null) writer.WriteElementString("Crp", XmlConvert.ToString(entity.Crp.Value));
                if (entity.Neomycin != null) writer.WriteElementString("Neomycin", XmlConvert.ToString(entity.Neomycin.Value));
                if (entity.Comment != null) writer.WriteElementString("Comment", entity.Comment);
            }
        }

        #endregion

        #region 默认Json序列化器类

        public class DefaultJsonSerializer : JsonSerializerBase, IEntityJsonSerializer<ChemistryImmunity>
        {
            ChemistryImmunity entity;
            public DefaultJsonSerializer(ChemistryImmunity entity)
                : base()
            {
                this.entity = entity;
            }

            public ChemistryImmunity Entity
            {
                get { return entity; }
                set { entity = value; }
            }

            /// <summary>
            /// 读取JSON属性
            /// </summary>
            /// <param name="propName">属性名称</param>
            /// <param name="propValue">属性值</param>
            /// <param name="reader">JSON读取器</param>
            protected override void ReadJsonProperty(string propName, object propValue, JsonReader reader)
            {
                switch (propName)
                {
                    case "id":
                        entity.id = DbConvert.ToNullableInt64(propValue) ?? entity.id;
                        break;
                    case "il2":
                        entity.il2 = DbConvert.ToNullableDecimal(propValue) ?? entity.il2;
                        break;
                    case "il6":
                        entity.il6 = DbConvert.ToNullableDecimal(propValue) ?? entity.il6;
                        break;
                    case "il8":
                        entity.il8 = DbConvert.ToNullableDecimal(propValue) ?? entity.il8;
                        break;
                    case "il10":
                        entity.il10 = DbConvert.ToNullableDecimal(propValue) ?? entity.il10;
                        break;
                    case "tnf":
                        entity.tnf = DbConvert.ToNullableDecimal(propValue) ?? entity.tnf;
                        break;
                    case "crp":
                        entity.crp = DbConvert.ToNullableDecimal(propValue) ?? entity.crp;
                        break;
                    case "neomycin":
                        entity.neomycin = DbConvert.ToNullableDecimal(propValue) ?? entity.neomycin;
                        break;
                    case "comment":
                        entity.comment = Convert.ToString(propValue) ?? entity.comment;
                        break;
                    case "timeStamp":
                        entity.timeStamp = new DateTime(DbConvert.ToNullableInt64(propValue) ?? 0);
                        break;
                }
            }

            /// <summary>
            /// 写入JSON属性
            /// </summary>
            /// <param name="writer">JSON编写器</param>
            protected override void WriteJsonProperties(JsonWriter writer)
            {

                //Id
                writer.WritePropertyName("id");
                writer.WriteValue(entity.Id);

                //Il2
                writer.WritePropertyName("il2");
                if (entity.Il2 == null)
                {
                    writer.WriteNull();
                }
                else
                {
                    writer.WriteValue(entity.Il2.Value);
                }

                //Il6
                writer.WritePropertyName("il6");
                if (entity.Il6 == null)
                {
                    writer.WriteNull();
                }
                else
                {
                    writer.WriteValue(entity.Il6.Value);
                }

                //Il8
                writer.WritePropertyName("il8");
                if (entity.Il8 == null)
                {
                    writer.WriteNull();
                }
                else
                {
                    writer.WriteValue(entity.Il8.Value);
                }

                //Il10
                writer.WritePropertyName("il10");
                if (entity.Il10 == null)
                {
                    writer.WriteNull();
                }
                else
                {
                    writer.WriteValue(entity.Il10.Value);
                }

                //Tnf
                writer.WritePropertyName("tnf");
                if (entity.Tnf == null)
                {
                    writer.WriteNull();
                }
                else
                {
                    writer.WriteValue(entity.Tnf.Value);
                }

                //Crp
                writer.WritePropertyName("crp");
                if (entity.Crp == null)
                {
                    writer.WriteNull();
                }
                else
                {
                    writer.WriteValue(entity.Crp.Value);
                }

                //内霉素(6-10pg/ml)
                writer.WritePropertyName("neomycin");
                if (entity.Neomycin == null)
                {
                    writer.WriteNull();
                }
                else
                {
                    writer.WriteValue(entity.Neomycin.Value);
                }

                //备注
                writer.WritePropertyName("comment");
                if (entity.Comment == null)
                {
                    writer.WriteNull();
                }
                else
                {
                    writer.WriteValue(entity.Comment);
                }

                //更新时间戳
                writer.WritePropertyName("timeStamp");
                writer.WriteValue(entity.TimeStamp.Ticks);
            }
        }


        #endregion
    }
}